.Net: Add Provider Support to ONNX Connector (+CUDA Sample)#12861
Merged
markwallace-microsoft merged 11 commits intoAug 7, 2025
Merged
Conversation
Member
|
@loicbtd Thanks for the contribution, I added some extra updates to this PR related to your change and other outstanding changes I had plan myself to add to the connector. Overall LTGM. |
rogerbarreto
approved these changes
Aug 5, 2025
Contributor
Author
|
Thanks for the update 👍 |
markwallace-microsoft
approved these changes
Aug 6, 2025
loicbtd
commented
Aug 7, 2025
markwallace-microsoft
approved these changes
Aug 7, 2025
ltwlf
pushed a commit
to ltwlf/semantic-kernel
that referenced
this pull request
Aug 9, 2025
…t#12861) ### Motivation and Context <!-- Thank you for your contribution to the semantic-kernel repo! Please help reviewers and future users, providing the following information: 1. Why is this change required? 2. What problem does it solve? 3. What scenario does it contribute to? 4. If it fixes an open issue, please link to the issue here. --> 1. **Why is this change required?** Currently, users can configure ONNX execution providers by manually creating a `genai_config.json` file next to the ONNX model. 2. **What problem does it solve?** This change eliminates the need for manual JSON configuration files by providing a programmatic API for provider configuration, making it easier for developers to configure ONNX execution providers directly through code with the extension methods. 3. **What scenario does it contribute to?** This improves the developer experience when working with ONNX models in Semantic Kernel, particularly for scenarios where: - Developers want to dynamically select providers based on runtime conditions - Teams prefer code-based configuration over file-based configuration 4. **If it fixes an open issue, please link to the issue here.** Closes microsoft#12828 ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> **Changes Made:** - **New Provider Class**: Added `Provider` class to encapsulate provider configuration with `Id` and `Options` properties - **Enhanced Chat Completion Service**: Extended `OnnxRuntimeGenAIChatCompletionService` to accept the providers parameter. - **Updated Builder Extension**: Modified `OnnxKernelBuilderExtensions.AddOnnxRuntimeGenAIChatCompletion` to accept the providers parameter. - **New Demo Project**: Created `OnnxWithProviderChoice` demo showcasing the new provider configuration API - **Package Configuration**: Add the Microsoft.ML.OnnxRuntime.Gpu package version in the Directory.Packages.props **Design Approach:** The implementation leverages ONNX Runtime GenAI's existing `Config` API to programmatically set providers and their options. The `Provider` class provides a clean abstraction for specifying provider ID (e.g., "cuda", "cpu") and custom options. During service initialization, the providers are configured using the underlying ONNX Runtime GenAI configuration system. **Usage Example:** ```csharp builder.AddOnnxRuntimeGenAIChatCompletion( modelId: "onnx", modelPath: modelPath, providers: [new Provider { Id = "cuda" }] ); ``` **Backward Compatibility:** This change maintains full backward compatibility. Existing code continues to work without modification, and the manual `genai_config.json` approach remains supported. ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [x] The code builds clean without any errors or warnings - [x] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [x] All unit tests pass, and I have added new tests where possible - [x] I didn't break anyone 😄 --------- Co-authored-by: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com>
jcruzmot-te
pushed a commit
to thousandeyes/aia-semantic-kernel
that referenced
this pull request
Sep 15, 2025
…t#12861) ### Motivation and Context <!-- Thank you for your contribution to the semantic-kernel repo! Please help reviewers and future users, providing the following information: 1. Why is this change required? 2. What problem does it solve? 3. What scenario does it contribute to? 4. If it fixes an open issue, please link to the issue here. --> 1. **Why is this change required?** Currently, users can configure ONNX execution providers by manually creating a `genai_config.json` file next to the ONNX model. 2. **What problem does it solve?** This change eliminates the need for manual JSON configuration files by providing a programmatic API for provider configuration, making it easier for developers to configure ONNX execution providers directly through code with the extension methods. 3. **What scenario does it contribute to?** This improves the developer experience when working with ONNX models in Semantic Kernel, particularly for scenarios where: - Developers want to dynamically select providers based on runtime conditions - Teams prefer code-based configuration over file-based configuration 4. **If it fixes an open issue, please link to the issue here.** Closes microsoft#12828 ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> **Changes Made:** - **New Provider Class**: Added `Provider` class to encapsulate provider configuration with `Id` and `Options` properties - **Enhanced Chat Completion Service**: Extended `OnnxRuntimeGenAIChatCompletionService` to accept the providers parameter. - **Updated Builder Extension**: Modified `OnnxKernelBuilderExtensions.AddOnnxRuntimeGenAIChatCompletion` to accept the providers parameter. - **New Demo Project**: Created `OnnxWithProviderChoice` demo showcasing the new provider configuration API - **Package Configuration**: Add the Microsoft.ML.OnnxRuntime.Gpu package version in the Directory.Packages.props **Design Approach:** The implementation leverages ONNX Runtime GenAI's existing `Config` API to programmatically set providers and their options. The `Provider` class provides a clean abstraction for specifying provider ID (e.g., "cuda", "cpu") and custom options. During service initialization, the providers are configured using the underlying ONNX Runtime GenAI configuration system. **Usage Example:** ```csharp builder.AddOnnxRuntimeGenAIChatCompletion( modelId: "onnx", modelPath: modelPath, providers: [new Provider { Id = "cuda" }] ); ``` **Backward Compatibility:** This change maintains full backward compatibility. Existing code continues to work without modification, and the manual `genai_config.json` approach remains supported. ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [x] The code builds clean without any errors or warnings - [x] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [x] All unit tests pass, and I have added new tests where possible - [x] I didn't break anyone 😄 --------- Co-authored-by: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
Why is this change required?
Currently, users can configure ONNX execution providers by manually creating a
genai_config.jsonfile next to the ONNX model.What problem does it solve?
This change eliminates the need for manual JSON configuration files by providing a programmatic API for provider configuration, making it easier for developers to configure ONNX execution providers directly through code with the extension methods.
What scenario does it contribute to?
This improves the developer experience when working with ONNX models in Semantic Kernel, particularly for scenarios where:
If it fixes an open issue, please link to the issue here.
Closes .Net: Add Provider Choice Support to ONNX Connector #12828
Description
Changes Made:
Providerclass to encapsulate provider configuration withIdandOptionspropertiesOnnxRuntimeGenAIChatCompletionServiceto accept the providers parameter.OnnxKernelBuilderExtensions.AddOnnxRuntimeGenAIChatCompletionto accept the providers parameter.OnnxWithProviderChoicedemo showcasing the new provider configuration APIDesign Approach:
The implementation leverages ONNX Runtime GenAI's existing
ConfigAPI to programmatically set providers and their options. TheProviderclass provides a clean abstraction for specifying provider ID (e.g., "cuda", "cpu") and custom options. During service initialization, the providers are configured using the underlying ONNX Runtime GenAI configuration system.Usage Example:
Backward Compatibility:
This change maintains full backward compatibility. Existing code continues to work without modification, and the manual
genai_config.jsonapproach remains supported.Contribution Checklist